package com.phiture.erp.basic.web.controller.api;

import cn.hutool.core.collection.CollUtil;
import com.phiture.erp.basic.api.pojo.resp.ErpMaterialPlanResp;
import com.phiture.erp.basic.api.service.ErpMaterialPlanApi;
import com.phiture.erp.basic.core.service.ErpMaterialPlanService;
import com.phiture.erp.basic.dal.entity.ErpMaterialPlanDO;
import com.phiture.erp.basic.web.convert.ErpMaterialPlanConvertMapper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author YH
 * @date 2025-05-06-11:12
 */

@Slf4j
@Service
@RequiredArgsConstructor
public class ErpMaterialPlanApiServiceImpl implements ErpMaterialPlanApi {
    private final ErpMaterialPlanService materialPlanService;

    @Override
    public List<ErpMaterialPlanResp> getMaterialPlanInfo(Collection<Long> materialIds) {
        List<ErpMaterialPlanDO> list = materialPlanService.getErpMaterialPlanInfo(materialIds);
        return ErpMaterialPlanConvertMapper.INSTANCE.toErpMaterialPlanRespList(list);
    }

    @Override
    public Map<Long, ErpMaterialPlanResp> getMaterialPlanMap(Collection<Long> materialIds) {
        List<ErpMaterialPlanResp> list = getMaterialPlanInfo(materialIds);
        return CollUtil.isEmpty(list) ? Collections.emptyMap() : list.stream().collect(Collectors.toMap(ErpMaterialPlanResp::getMaterialId, obj -> obj));
    }
}
